package com.haifeng.im;


public class MyTextBuilder {


    public static void main(String[] args) {
        Builder builder=new ApplePCBuilder();
        Director director=new Director(builder);
        director.construct(1,2,"doms");
        System.out.println(builder.create().toString());
    }
}

abstract class Computer {
    protected int mCpuCore = 1;
    protected int mRamSize = 0;
    protected String mOs = "Dos";

    protected Computer() {
    }

    public abstract void setCpu(int core);

    public abstract void setRam(int size);

    public abstract void setOs(String os);

    @Override
    public String toString() {
        return "Computer[mcpucore=" + mCpuCore + ",mramsize=" + mRamSize + ",mos=" + mOs + "]";
    }

}

class AppleComputer extends Computer {

    protected AppleComputer() {
    }

    @Override
    public void setCpu(int core) {
        this.mCpuCore = core;
    }

    @Override
    public void setRam(int size) {
        this.mRamSize = size;
    }

    @Override
    public void setOs(String os) {
        this.mOs = os;
    }

}

abstract class Builder {
    public abstract void buildCpu(int cpu);

    public abstract void buildRam(int ram);

    public abstract void buildOs(String os);

    public abstract Computer create();
}

class ApplePCBuilder extends Builder {
    private Computer mApplePC = new AppleComputer();


    @Override
    public void buildCpu(int cpu) {
        mApplePC.setCpu(cpu);

    }

    @Override
    public void buildRam(int ram) {
        mApplePC.setRam(ram);
    }

    @Override
    public void buildOs(String os) {
        mApplePC.setOs(os);
    }

    @Override
    public Computer create() {
        return mApplePC;
    }
}

class Director {
    Builder builder = null;

    public Director(Builder builder) {
        this.builder = builder;
    }
    public void construct(int cpu,int ram,String os){
        builder.buildCpu(cpu);
        builder.buildRam(ram);
        builder.buildOs(os);
    }
}